package game.util;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MultipliedPrintStream
{
    private List<PrintStream> printStreams = Collections.synchronizedList(new ArrayList<PrintStream>());
    
    public void add(PrintStream stream)
    {
        synchronized (printStreams)
        {
            printStreams.add(stream);
        }
    }
    
    public boolean remove(PrintStream stream)
    {
        boolean r = false;
        synchronized (printStreams)
        {
            r = printStreams.remove(stream);
        }
        return r;
    }
    
    public void println()
    {
        synchronized (printStreams)
        {
            for (PrintStream s : printStreams)
            {
                s.println();
            }
        }
    }

    public void println(String string)
    {
        synchronized (printStreams)
        {
            for (PrintStream s : printStreams)
            {
                s.println(string);
            }
        }
    }

    public void print(String string)
    {
        synchronized (printStreams)
        {
            for (PrintStream s : printStreams)
            {
                s.print(string);
            }
        }
    }
}
